
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" href="/static/layui/css/layui.css">
    <script src="/static/layui/layui.js"></script>
    <script src="/static/jquery-3.6.3.min.js"></script>
    <script src="/static/fun.js"></script>
</head>
<body>
<!--操作按钮模板-->

<form class="layui-form" action=""style="padding: 50px 40px">
    <div class="layui-form-item">
        <label class="layui-form-label">标题</label>
        <div class="layui-input-block">
            <input type="text" name="Title" required  lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <input type="text" name="Context" required  lay-verify="required" placeholder="请输入描述" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">轮播图</label>
        <div class="layui-input-inline">
            <img class="img-Carousel" src="" style="width: 150px;height: 150px">
            <input style="display: none" class="input-Carousel" type="text" name="Url" required  lay-verify="required" placeholder="请输入描述" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-input-inline layui-btn-container" style="width: auto;">
            <button type="button" class="layui-btn layui-btn-primary" id="LAY_CarouselUpload">
                <i class="layui-icon"></i>上传图片
            </button><input  class="layui-upload-file" type="file" accept="" name="file">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">链接</label>
        <div class="layui-input-block">
            <input type="text" name="Link" required  lay-verify="required" placeholder="请输入链接" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="Carousel-Add">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
<script>
    layui.use("form",function (){
        var form = layui.form;
        form.on('submit(Carousel-Add)',function (data){
            $.ajax({
                url:'/teacher/Carousel/add',
                method:'post',
                data:data.field,
                dataType:'JSON',
                async: false,
                success:function(res){
                        layer.msg("提交成功",{icon: 1, time: 1000},function(){
                            window.parent.location.reload()
                        }); //提交成功后刷新页面
                }
            });
            return false;
        })
    })
    layui.use('upload', function(){
        var upload = layui.upload;
        var mydata = new Date();
        var Nowtime = mydata.getDate()+mydata.getTime()
        //执行实例
        var uploadInst = upload.render({
            elem: '#LAY_CarouselUpload' //绑定元素
            ,url: '/public/uploadCarousel/'+Nowtime //上传接口
            ,data:{  // 文件上传的参数
                id: Nowtime,
                Status:"轮播图",
            }
            ,done: function(res){
                layer.msg(res.msg,{icon: res.icon, time: 1000},function(){
                    $(".img-Carousel").attr("src","/static/images/carousel/"+Nowtime+".png")
                    $(".input-Carousel").val("/static/images/carousel/"+Nowtime+".png")
                }); //提交成功后刷新页面
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });
</script>

</body>
